package com.bwie.es.controller;

import com.alibaba.fastjson.JSONObject;
import com.bwie.common.domain.Book;
import com.bwie.common.domain.request.BookRequest;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.es.service.EsBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Slf4j
public class EsBookController {

    @Autowired
    private EsBookService esBookService;

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/searchBook")
    public Result<PageResult<Book>> searchBook(@RequestBody BookRequest bookRequest){
        log.info("功能名称:Es全局搜索,请求URI:{},请求方式:{},请求参数:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(bookRequest));
        Result<PageResult<Book>> pageResultResult = esBookService.searchBook(bookRequest);
        log.info("功能名称:Es全局搜索,请求URI:{},请求方式:{},响应结果:{}",
                request.getRequestURI(),
                request.getMethod(),
                JSONObject.toJSONString(bookRequest));
        return pageResultResult;
    }






}
